﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2011
 */

#region Using

using System.Data.OracleClient;
using System.ComponentModel;
using NetBay.Core.DataAccess;
using NetBay.Core.Extensions;
using System.Data;
using Rio.Framework.RioManager;
#endregion

namespace Rio.Doc.DataAccess
{
    public class DA_Erp
    {

        #region Enum
        /// <summary>
        /// List of DB functions to access data
        /// </summary>
        public enum DbFunction
        {
            [DescriptionAttribute("")]
            None,
            [DescriptionAttribute("P_GENESIS_Folder_Get")]             
            GetGenesisGetFolder,
            [DescriptionAttribute("P_ERP_PARAM_Get")]               
            GetErpParam, 
            [DescriptionAttribute("P_GENESIS_Folder_Check")]        
            GetGenesisFolderCheck, 
            [DescriptionAttribute("P_GENESIS_Folder_Exist")]
            GetGenesisFolderExist,
            [DescriptionAttribute("P_ERP_CONN_Get_ByName")]
            GetErpConnByName

        }
        #endregion




        /// <summary>
        /// Return Orga, td and Td Name
        /// </summary>
        /// <param name="p_sConnectorName"></param>
        /// <returns></returns>
        public static IDataReader GetOrgaByErpName(string p_sConnectorName)
        {

            var db = DbHelper.DataBase;
            var dbCommand = db.GetStoredProcCommand(DbFunction.GetErpConnByName.szGetDescription());

            db.AddInParameter(dbCommand, "p_sErpConnName", DbType.String, p_sConnectorName);

            return db.ExecuteReader(dbCommand);
        }


        /// <summary>
        /// Return this TD of organisation
        /// </summary>
        /// <param name="s_lAction"></param>
        /// <param name="s_lOrganizationName"></param>
        /// <param name="s_lCodeCourrierGenesis"></param>
        /// <param name="s_lImageName"></param>
        /// <returns></returns>
        public static IDataReader GetGenesisFolder(string p_sConnectorName)
        {
            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetGenesisGetFolder.szGetDescription());

            db.AddInParameter(dbCommand, "p_sConnectorName", DbType.String, p_sConnectorName);

            return db.ExecuteReader(dbCommand);
        }


        /// <summary>
        /// Return param with erp and rioWeb (r_erp_param)
        /// </summary>
        /// <param name="p_sValue"></param>
        /// <returns></returns>
        public static IDataReader GetErpParam(string p_sValue, int p_iOrga, int p_iTd)
        {

            var db = DbHelper.DataBase;

            var dbCommand = db.GetNewCommand(DbFunction.GetErpParam.szGetDescription());

            db.AddInParameter(dbCommand, "p_sErpValue", DbType.String, p_sValue);
            db.AddInParameter(dbCommand, "p_lEntityId", DbType.Int32, p_iOrga);
            db.AddInParameter(dbCommand, "p_lFolderTypeId", DbType.Int32, p_iTd);

            return db.ExecuteReader(dbCommand);
        }


        /// <summary>
        /// Return individu(ASA) or Folder(Different de ASA)
        /// </summary>
        /// <param name="s_lTdTableName"></param>
        /// <param name="s_lIndividu"></param>
        /// <param name="s_lIndexPosit"></param>
        /// <returns></returns>
        public static IDataReader GetGenesisIndividuExist(string s_lTdTableName, string s_lIndividu, string s_lIndexPosit)
        {

            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetGenesisFolderCheck.szGetDescription());

            db.AddInParameter(dbCommand, "p_sNameTD", DbType.String, s_lTdTableName);
            db.AddInParameter(dbCommand, "p_sFolderIndividu", DbType.String, s_lIndividu);
            db.AddInParameter(dbCommand, "p_sIndexPosit", DbType.String, s_lIndexPosit);

            return db.ExecuteReader(dbCommand);

        }


        /// <summary>
        /// Return id courrierId exist
        /// </summary>
        /// <param name="s_lCourrierIdErp"></param>
        /// <param name="s_lTdTableName"></param>
        /// <param name="s_lIndividu"></param>
        /// <param name="s_lIndexPosit"></param>
        /// <returns></returns>
        public static IDataReader GetGenesisFolderExist(string s_lCourrierIdErp, string s_lTdTableName, string s_lIndividu, string s_lIndexPosit)
        {

            var db = DbHelper.DataBase;
            var dbCommand = db.GetNewCommand(DbFunction.GetGenesisFolderExist.szGetDescription());

            db.AddInParameter(dbCommand, "p_sCourrierIdErp", DbType.String, s_lCourrierIdErp);
            db.AddInParameter(dbCommand, "p_sNameTD", DbType.String, s_lTdTableName);
            db.AddInParameter(dbCommand, "p_sFolderIndividu", DbType.String, s_lIndividu);
            db.AddInParameter(dbCommand, "p_sIndexPosit", DbType.String, s_lIndexPosit);
            return db.ExecuteReader(dbCommand);

        }

    }
}
